package com.maegul.web.components;

import java.text.NumberFormat;
import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;

import com.maegul.data.entities.CartItem;
import com.maegul.web.MaegulSession;

public class TotalPanel extends Panel {

	private static final long serialVersionUID = 1L;

	public TotalPanel(String id) {
		super(id);

		add(new Label("total", new Model<String>() {

			private static final long serialVersionUID = 1L;

			@Override
			public String getObject() {
				NumberFormat nf = NumberFormat.getCurrencyInstance();
				List<CartItem> cart = MaegulSession.get().getCart();
				double total = 0;

				for (CartItem item : cart) {
					total += item.getMediaItem().getPrice();
				}

				return nf.format(total);
			}
		}));
	}

}
